home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_07 / 1n07068a < prev    next >
Text File  |  1990-09-10  |  3KB  |  82 lines

  1.         page    55, 132
  2.  
  3. ;
  4. ;  Figure 4 - Joystick support functions
  5. ;
  6. ;  Requires MASM 5.1 or later
  7. ;
  8.  
  9. %       .MODEL  memodel,lang            ;Add model and language support via
  10.                                         ;command line macros,
  11.                                         ;e.g. MASM /Dmemodel=LARGE /Dlang=C
  12.  
  13.         .CODE
  14.  
  15. ;
  16. ;  Read the joystick switch settings
  17. ;
  18. ;  Arguments: none
  19. ;  Returns:   Switch status in bits 0-3
  20. ;             Error: -1
  21. ;
  22. JOYsw   PROC    USES DX
  23.         mov     ah,84h                  ;Set up interrupt
  24.         xor     dx,dx                   ;Subfunction 0 reads the switches
  25.         int     15h
  26.         jc      err1                    ;PC, PCjr, & PC/XT 11/08/82 come here
  27.         shr     al,1                    ;Move switches from bits 4-7...
  28.         shr     al,1
  29.         shr     al,1
  30.         shr     al,1                    ;...to bits 0-3
  31.         xor     ah,ah                   ;Clear hi byte
  32.         ret
  33. err1:
  34.         mov     ax,-1                   ;Return 0FFFFh for error
  35.         ret
  36. JOYsw   ENDP
  37.  
  38. ;
  39. ;  Read joystick position
  40. ;
  41. ;  Arguments: Pointer to X value of A joystick
  42. ;             Pointer to Y value of A joystick
  43. ;             Pointer to X value of B joystick
  44. ;             Pointer to Y value of B joystick
  45. ;  Returns:   0 if successful, else -1
  46. JOYpos  PROC    USES BX CX DX ES, a_x:PTR, a_y:PTR, b_x:PTR, b_y:PTR
  47.         mov     ah,84h
  48.         mov     dx,1                    ;Subfunction 1 to read positions
  49.         int     15h
  50.         jc      err2                    ;PC, PCjr, & PC/XT 11/08/82 come here
  51.     IF @DataSize                        ;(Far pointers)
  52.         push    bx                      ;Save A(Y)
  53.         les     bx,a_x                  ;Store A(X)
  54.         mov     es:[bx],ax
  55.         pop     ax                      ;Store A(Y)
  56.         les     bx,a_y
  57.         mov     es:[bx],ax
  58.         les     bx,b_x                  ;Store B(X)
  59.         mov     es:[bx],cx
  60.         les     bx,b_y                  ;Store B(Y)
  61.         mov     es:[bx],dx
  62.     ELSE                                ;(Near pointers)
  63.         push    bx                      ;Save A(Y)
  64.         mov     bx,a_x                  ;Store A(X)
  65.         mov     [bx],ax
  66.         pop     ax                      ;Store A(Y)
  67.         mov     bx,a_y
  68.         mov     [bx],ax
  69.         mov     bx,b_x                  ;Store B(X)
  70.         mov     [bx],cx
  71.         mov     bx,b_y                  ;Store B(Y)
  72.         mov     [bx],dx
  73.     ENDIF
  74.         xor     ax,ax                   ;Return 0 for success
  75.         ret
  76. err2:
  77.         mov     ax,-1                   ;Return 0FFFFh for error
  78.         ret
  79. JOYpos  ENDP
  80.  
  81.         end
  82.